#include <iostream>
#include <string>
#include <thread>
using namespace std;

int longestSubstring(string s, int k)
{
    char alp[26] = { 0 };
    for (auto p = s.begin(); p != s.end(); ++p) {
	++alp[*p - 'a'];
    }
    unsigned left = 0;
    unsigned right = 0;
    unsigned max_len = right - left + 1;
    while (right <= s.size() - 1) {
	if (alp[s[right] - 'a'] >= k) {
	    if (right - left + 1 > max_len) {
		max_len = right - left + 1;
	    }
	    ++right;
	} else {
	    ++right;
	    left = right;
	}
    }
    return max_len;
}

int main()
{
	string s = "ababbc";
	cout<<longestSubstring(s,3)<<endl;
}
